<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Home\Widget;
use Think\Action;

/**
 * 分类widget
 * 用于动态调用分类信息
 */

class CategoryWidget extends Action{
	
	/* 显示指定分类的同级分类或子分类列表 */
	public function lists($cate, $child = true){
		$field = 'id,name,pid,title,link_id';
		if($child){
			$category = D('Category')->getTree($cate, $field);
			$category = $category['_'];
		} else {
			$category = D('Category')->getSameLevel($cate, $field);
		}

        //print_r($cate);

        //获取当前用户，所在用户组，的对应菜单可见项
        $authAry = session("user_auth");
        $uid = $authAry["uid"];
        $auth_categories = D('AuthGroup')->getAuthCategories($uid);
        //print_r($authAry);
        //print_r($uid);
        //print_r($auth_categories);
        //echo "+++".$demo->getAuthCategories();
        //$auth_categories = D('AuthGroup')->getAuthCategories($authAry["uid"]);

        $categoryAll = D('Category')->getTreeAll(0, true, $auth_categories);
        //print_r($categoryAll);

        $category2 = D('Category')->getTree2(0, true, $auth_categories);

        if (is_array($category2[0]["_"]) > 0)
        {
            $category2 = $category2[0]["_"];
        }
        //print_r($category2);

        $this->assign('auth_categories', $auth_categories);
        $this->assign('category2', $category2);
		$this->assign('category', $category);
		$this->assign('current', $cate);
        $this->assign('categoryAll', $categoryAll);
        session('current', $cate);
		$this->display('Category/lists');
	}
	
}
